package com.ddwl.funds.dao;

import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.dao.TkDao;
import com.ddwl.funds.dao.mapper.OrderAliPayMapper;
import com.ddwl.funds.dao.model.OrderAliPay;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 阿里支付表(OrderAliPay)数据处理
 *
 * @author zach
 * @since 2020-09-24 11:42:01
 */
@Repository
public class OrderAliPayDao  extends TkDao<OrderAliPayMapper, OrderAliPay> {



    /**
     * 获取正在支付的数据
     * @param orderPayId
     * @return
     */
    public OrderAliPay nowPay(String orderPayId){
        Example example = new Example(OrderAliPay.class);
        example.and().andEqualTo("outTradeNo",orderPayId)
                .andEqualTo("dflag", BaseEnum.DflagEnum.NOT_DELETE.getCode());
        example.setOrderByClause("gmt_created desc limit 1");
        List<OrderAliPay> aliPays = baseMapper.selectByExample(example);
        if(CollectionUtils.isEmpty(aliPays)){
            return null;
        }
        return aliPays.get(0);
    }
}